package com.swh;

import com.swh.config.ReidsConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/25 11:06
 * @Version: 1.0
 */
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ReidsConfig.class)
public class Redis {
    @Autowired
    private RedisTemplate<String, Object> template;

    @Test
    public void modes1() {
        SetOperations<String, Object> forSet = template.opsForSet();

        forSet.add("testSet", "小明");
        Long testSet = forSet.size("testSet");
        System.out.println(testSet);
    }

    @Test
    public void modes2() {
        ValueOperations<String, Object> forValue = template.opsForValue();
        Map<String, Object> map = new HashMap<>();
        map.put("name","李白");
        map.put("pass","123456");
        forValue.set("user", map);

        Object set = forValue.get("user");
        System.out.println(set);
    }


}
